package org.magicsoft.office.excel.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ResultSummary {

	private int fileCount = 0;

	private int sheetCount = 0;

	private int dataCount = 0;

	private int insertCount = 0;

	private int updateCount = 0;

	private Date beginDate = null;

	private Date endDate = null;

	private List<ResultItem> items = null;

	public int getFileCount() {
		return fileCount;
	}

	public void addFileCount(int n) {
		this.fileCount += n;
	}

	public int getSheetCount() {
		return sheetCount;
	}

	public void addSheetCount(int n) {
		this.sheetCount += n;
	}

	public int getDataCount() {
		return dataCount;
	}

	public int getInsertCount() {
		return insertCount;
	}

	public int getUpdateCount() {
		return updateCount;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public void addItem(ResultItem resultItem) {
		if (this.items == null) {
			this.items = new ArrayList<>();
		}
		this.addDataCount(resultItem.getInsertCount() + resultItem.getUpdateCount());
		this.addInsertCount(resultItem.getInsertCount());
		this.addUpdateCount(resultItem.getUpdateCount());
		this.items.add(resultItem);
	}

	public List<ResultItem> getItems() {
		return items;
	}

	public String getElapsedTime() {
		if (this.beginDate != null && this.endDate != null) {
			return String.valueOf((this.endDate.getTime() - this.beginDate.getTime()) / 1000);
		}
		return null;
	}

	private void addDataCount(int n) {
		this.dataCount += n;
	}

	private void addInsertCount(int n) {
		this.insertCount += n;
	}

	private void addUpdateCount(int n) {
		this.updateCount += n;
	}

}
